{% extends 'TopxiaWebBundle:Default:layout.html.twig' %}

{% block topbanner %}
  {% set blocks = data('Blocks',{'codes':['autumn:home_top_banner'] }) %}
  {% if blocks['autumn:home_top_banner'] %}
    <div id="autumn-carousel" class="carousel slide hidden-xs mbl" data-ride="carousel">
      <ol class="carousel-indicators">
          <li data-target="#autumn-carousel" data-slide-to="0" class="active"></li>
          <li data-target="#autumn-carousel" data-slide-to="1" class=""></li>
          <li data-target="#autumn-carousel" data-slide-to="2" class=""></li>
      </ol>
      <div class="carousel-inner">{{ blocks['autumn:home_top_banner']|raw }}</div>
      <a class="left carousel-control" href="#autumn-carousel" data-slide="prev">
          <span class="glyphicon glyphicon-chevron-left"></span>
      </a>
      <a class="right carousel-control" href="#autumn-carousel" data-slide="next">
          <span class="glyphicon glyphicon-chevron-right"></span>
      </a>
    </div>
  {% endif %}

{% endblock %}

{% block content %}
  <div class="row">
    <div class="col-lg-12">
      <div class="panel panel-autumn panel-autumn-primary">
        <div class="panel-heading panel-heading-important">
          <h2 class="panel-title">推荐课程 / <small>RecommendCourse</small></h2>
        </div>
        <div class="panel-body">
          <ul class="autumn-grids">
            {% for course in data('RecommendCourses',{ count:8 }) %}
              {% if course %}
                <li class="autumn-grid autumn-course-grid">
                  <a href="{{ path('course_show', {id:course.id}) }}" class="course-picture"><img src="{{ file_path(course.largePicture, 'course-large.png') }}">
                    {% if course.serializeMode == 'serialize' %}
                      <span class="label label-success series-mode-label">更新中</span>
                    {% elseif course.serializeMode == 'finished' %}
                      <span class="label label-warning series-mode-label">已完结</span>
                    {% endif %}
                  </a>
                  <h3 class="course-name"><a href="{{ path('course_show', {id:course.id}) }}">{{ course.title }}</a></h3>
                  <div class="course-about">{{ course.about|plain_text(60) }}</div>

                  <div class="course-metas">
                    <span class="price">{% if course.price > 0 %}{{ course.price }}元{% else %}免费{% endif %}</span>
                    <span class="teachers">
                      {% for teacher in course.teachers %}
                        {{ web_macro.user_link(teacher, 'text-muted') }}
                      {% endfor %}
                    </span>
                  </div>
                </li>
              {% else %}
                <div class="empty">无推荐课程，请在后台课程管理设置。</div>
              {% endif %}
            {% endfor %}
          </ul>
        </div>
      </div>
    </div>
  </div>

  <div class="row">
    <div class="col-md-8">
      <div class="panel panel-autumn panel-autumn-default">
        <div class="panel-heading panel-heading-important">
          <h2 class="panel-title">最新课程 / <small>LatestCourse</small></h2>
        </div>
        <div class="panel-body">
          <ul class="media-list autumn-course-list">
            {% for course in data('LatestCourses',{ count:8 }) %}
              {% if course %}
              <li class="media">
                <a href="{{ path('course_show', {id:course.id}) }}" class="pic-link pull-left hidden-xs"><img src="{{ file_path(course.largePicture, 'course-large.png') }}" class="media-object">
                  {% if course.serializeMode == 'serialize' %}
                    <span class="label label-success series-mode-label">更新中</span>
                  {% elseif course.serializeMode == 'finished' %}
                    <span class="label label-warning series-mode-label">已完结</span>
                  {% endif %}
                </a>
                <div class="media-body">
                  <h4 class="media-heading"><a href="{{ path('course_show', {id:course.id}) }}">{{ course.title }}</a></h4>

                  <div class="course-about"><p>{{ course.about|plain_text(100) }}</p></div>
                  <div class="course-metas">
                    <span class="price">{% if course.price > 0 %}{{ course.price }}元{% else %}免费{% endif %}</span>
                    <span class="teachers">
                      <span class="glyphicon glyphicon-user text-muted"></span> <span class="text-muted">老师</span>
                      {% for teacher in course.teachers %}
                        {{ web_macro.user_link(teacher, 'text-muted') }}
                      {% endfor %}
                    </span>
                  </div>
                </div>
              </li>
              {% else %}
                <div class="empty">尚未发布课程，请先发布。</div>
              {% endif %}
            {% endfor %}
          </ul>
          <a class="btn btn-default btn-lg btn-block" href="{{ path('course_explore') }}">更多课程</a>
        </div>
      </div>

      {% if setting('course.live_course_enabled') %}
      <div class="panel panel-autumn panel-autumn-default">
        <div class="panel-heading panel-heading-important">
          <h2 class="panel-title">近期直播 / <small>LiveCourse</small></h2>
        </div>
        <div class="panel-body">
          <ul class="media-list autumn-course-list">
            {% for course in recentLiveCourses %}
            {% set lesson = course.lesson %}
            <li class="media">
              <a href="{{ path('course_show', {id:course.id}) }}" class="pic-link pull-left hidden-xs"><img src="{{ file_path(course.largePicture, 'course-large.png') }}" class="media-object">
                {% if course.serializeMode == 'serialize' %}
                  <span class="label label-success series-mode-label">更新中</span>
                {% elseif course.serializeMode == 'finished' %}
                  <span class="label label-warning series-mode-label">已完结</span>
                {% endif %}
                {% if course.type == 'live' %}
                  {% if lesson and "now"|date("U") >= lesson.startTime and "now"|date("U") <= lesson.endTime %}
                    <span class="label label-warning series-mode-label">直播中</span>
                  {% else %}
                    <span class="label label-success series-mode-label">直播</span>
                  {% endif %}
                {% endif %}
              </a>
              <div class="media-body">
                <h4 class="media-heading"><a href="{{ path('course_show', {id:course.id}) }}">{{ course.title }}</a></h4>
                <div class="live-course-lesson">
                  <span class="live-time mrm">{{ lesson.startTime|date('n月j日 H:i') }} ~ {{ lesson.endTime|date('H:i') }}</span>
                  <span class="text-warning mrs">课时{{ lesson.number }}</span>
                </div>

                <div class="course-about"><p>{{ course.about|plain_text(100) }}</p></div>
                <div class="course-metas">
                  <span class="price">{% if course.price > 0 %}{{ course.price }}元{% else %}免费{% endif %}</span>
                  <span class="teachers">
                    <span class="glyphicon glyphicon-user text-muted"></span> <span class="text-muted">老师</span>
                    {% for teacher in course.teachers|default([]) %}
                      {{ web_macro.user_link(teacher, 'text-muted') }}
                    {% endfor %}
                  </span>
                </div>
              </div>
            </li>
            {% endfor %}
          </ul>
          {% if recentLiveCourses|length >= 1 %}
            <a class="btn btn-default btn-lg btn-block" href="{{ path('live_course_explore') }}">更多直播课程</a>
          {% endif %}
        </div>
      </div>
      {% endif %}
    </div>

    <div class="col-md-4">
      <div class="panel panel-autumn panel-autumn-default">
        <div class="panel-heading">
          <h4 class="panel-title">课程排行榜 / <small>Top10</small></h4>
        </div>
        <div class="panel-body">
          <ul class="media-list media-list-rank">
            {% for course in data('CourseRankByHit',{'count':10}) %}
              {% if course %}
                <li class="media">
                  <a href="{{ path('course_show', {id:course.id}) }}" class="pull-left"><img src="{{ file_path(course.largePicture, 'course-large.png') }}" class="media-object"></a>
                  <div class="media-body">
                    <h4 class="media-heading"><a href="{{ path('course_show', {id:course.id}) }}">{{ course.title }}</a></h4>
                    {{ course.subtitle }}
                  </div>
                </li>
              {% else %}
                <div class="empty">无课程排行记录</div>
              {% endif %}
            {% endfor %}
          </ul>
        </div>
      </div>
    </div>

  </div>

  <div class="row">
    <div class="col-lg-12">
      <div class="panel panel-autumn panel-autumn-primary">
          <div class="panel-heading panel-heading-important">
            <h2 class="panel-title">
                讲师团 / <small>Teachers</small>
            </h2>
          </div>
          <div class="panel-body">
            <ul class="autumn-grids">
              {% for teacher in data('RecommendTeachers',{'count':'8'}) %}
                {% if teacher %} 
                  <li class="autumn-grid">
                    <div class="media teacher-media">
                      <a href="{{ path('user_show', {id:teacher.id}) }}" class="pull-left"><img class="media-object" src="{{ file_path(teacher.mediumAvatar, 'avatar.png') }}"></a>
                      <div class="media-body">
                        <h4 class="media-heading">{{ web_macro.user_link(teacher) }}</h4>
                        <div class="teacher-title">{{ teacher.title }}</div>
                      </div>
                    </div>
                  </li>
                {% else %}
                  <div class="empty">尚未设置推荐老师，请在管理后台设置。</div>
                {% endif %}
              {% endfor %}
            </ul>
          </div>
      </div>
    </div>
  </div>

{% endblock %}